package com.xty.xtyle.analysis;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.google.android.material.tabs.TabLayout;
import com.xty.xtyle.R;
import com.xty.xtyle.base.AnalysisTabFragment;
import com.xty.xtyle.base.FmPagerAdapter;
import com.xty.xtyle.db.cloth.Cloth;
import com.xty.xtyle.db.cloth.ClothDao;
import com.xty.xtyle.db.mix.MixCloth;
import com.xty.xtyle.db.mix.MixDao;

import java.util.ArrayList;
import java.util.List;

public class AnalysisActivity extends AppCompatActivity {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private FmPagerAdapter pagerAdapter;
    private List<Fragment> fragments = new ArrayList<>();
    private String[] types = {"类型","颜色","面料","季节","品牌","状态","穿戴","价格"};
    public static final int PIC_STATE_BACK = 0x32;
    public static final int PIC_STATE_REQUEST = 0x31;
    public static final String PIC_STATE_POSITION = "position";

    public List<Cloth> cloths;

    public static void startActivity(Activity context) {
        Intent intent = new Intent(context, AnalysisActivity.class);
        context.startActivityForResult(intent, PIC_STATE_REQUEST);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_analysis);

        ClothDao dao = new ClothDao();
        cloths = dao.findAll();
        init();
    }

    private void init() {

        tabLayout = findViewById(R.id.tablayout);
        viewPager = findViewById(R.id.viewpager);

        for(int i=0;i<types.length;i++){
            AnalysisTabFragment tabFragment = new AnalysisTabFragment();
            Bundle args = new Bundle();
            args.putString("type", types[i]);
            tabFragment.setArguments(args);
            fragments.add(tabFragment);
            tabLayout.addTab(tabLayout.newTab());
        }

        tabLayout.setupWithViewPager(viewPager,false);
        pagerAdapter = new FmPagerAdapter(fragments, getSupportFragmentManager());
        viewPager.setAdapter(pagerAdapter);

        for(int i=0;i<types.length;i++){
            tabLayout.getTabAt(i).setText(types[i]);
        }
    }

}